//
//  FragHeader.cc
//  
//
//  Created by Henklajd on 5/10/13.
//
//

#include "FragmentationHeader.h"
NS_LOG_COMPONENT_DEFINE ("FragHeader");

namespace ns3 {
    
    
    NS_OBJECT_ENSURE_REGISTERED (FragHeader);
    FragHeader::FragHeader()
    {
        NS_LOG_FUNCTION (this);
    }
    
    
    FragHeader::FragHeader (uint32_t p_id,uint32_t p_n)
    {
        NS_LOG_FUNCTION (this);
        packet_ID=p_id;
        packet_Seq_Num=p_n;
    }
    
    uint32_t  FragHeader::GetData(uint32_t &p_id)
    {
        p_id=packet_ID;
        return packet_Seq_Num;
    }
    
    TypeId
    FragHeader::GetTypeId (void)
    {
        static TypeId tid = TypeId ("ns3::FragHeader")
        .SetParent<Header> ()
        .AddConstructor<FragHeader> ()
        ;
        return tid;
    }
    TypeId
    FragHeader::GetInstanceTypeId (void) const
    {
        return GetTypeId ();
    }
    void
    FragHeader::Print (std::ostream &os) const
    {
        NS_LOG_FUNCTION (this << &os);
    }
    uint32_t
    FragHeader::GetSerializedSize (void) const
    {
        NS_LOG_FUNCTION (this);
        
        return 4+4;
    }
    
    void
    FragHeader::Serialize (Buffer::Iterator start) const
    {
        NS_LOG_FUNCTION (this << &start);
        Buffer::Iterator j = start;
        j.Prev(GetSerializedSize());
                
        j.WriteU32 (packet_ID);
        j.WriteU32(packet_Seq_Num);
        
    }
    uint32_t
    FragHeader::Deserialize (Buffer::Iterator start)
    {
        NS_LOG_FUNCTION (this << &start);
        Buffer::Iterator j = start;
    if(!j.IsStart())
       j.Prev(8);
        
        packet_ID=j.ReadU32();

        packet_Seq_Num=j.ReadU32();
                
        return GetSerializedSize ();
    }
    
} // namespace ns3
